<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
































<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=6.6.0" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.6.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=6.6.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=6.6.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.6.0" color="#222">









<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '6.6.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="touch命令不常用，一般在使用 make 的时候可能会用到，用来修改文件时间戳，或者新建一个空文件。">
<meta name="keywords" content="Linux,Shell,每天一个Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="每天一个Linux命令（5）：touch">
<meta property="og:url" content="http://seveninsight.github.io/blog/2019/01/04/每天一个Linux命令（5）：touch/index.html">
<meta property="og:site_name" content="七年弹指间的博客">
<meta property="og:description" content="touch命令不常用，一般在使用 make 的时候可能会用到，用来修改文件时间戳，或者新建一个空文件。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-01-04T15:00:24.846Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="每天一个Linux命令（5）：touch">
<meta name="twitter:description" content="touch命令不常用，一般在使用 make 的时候可能会用到，用来修改文件时间戳，或者新建一个空文件。">






  <link rel="canonical" href="http://seveninsight.github.io/blog/2019/01/04/每天一个Linux命令（5）：touch/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>每天一个Linux命令（5）：touch | 七年弹指间的博客</title>
  












  <noscript>
  <style>
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion .logo-line-before i { left: initial; }
    .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">七年弹指间的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">知是行之始，行是知之成</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/blog/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/blog/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/blog/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/blog/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://seveninsight.github.io/blog/blog/2019/01/04/每天一个Linux命令（5）：touch/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="七年弹指间">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="七年弹指间的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">每天一个Linux命令（5）：touch

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-01-04 22:18:45 / 修改时间：23:00:24" itemprop="dateCreated datePublished" datetime="2019-01-04T22:18:45+08:00">2019-01-04</time>
            

            
              

              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing"><a href="/blog/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a></span>

                
                
                  ，
                
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing"><a href="/blog/categories/Linux/每天一个Linux命令/" itemprop="url" rel="index"><span itemprop="name">每天一个Linux命令</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><code>touch</code>命令不常用，一般在使用 make 的时候可能会用到，用来修改文件时间戳，或者新建一个空文件。</p>
<a id="more"></a>
<h2 id="1-功能"><a href="#1-功能" class="headerlink" title="1 功能"></a>1 功能</h2><p><code>touch</code>命令有两个功能：</p>
<ul>
<li>一是用于更改文件或目录的日期时间，包括存取时间和更改时间，它们的数据将原封不动地保留下来</li>
<li>二是用来创建新的空文件</li>
</ul>
<h2 id="2-语法格式"><a href="#2-语法格式" class="headerlink" title="2 语法格式"></a>2 语法格式</h2><pre><code>touch [选项] [参数]
</code></pre><p>【选项说明】</p>
<pre><code>-a：或--time=atime或--time=access或--time=use  只更改存取时间；
-c：或--no-create  不建立任何文件；
-d：&lt;时间日期&gt; 使用指定的日期时间，而非现在的时间；
-f：此参数将忽略不予处理，仅负责解决BSD版本touch指令的兼容性问题；
-m：或--time=mtime或--time=modify  只更该变动时间；
-r：&lt;参考文件或目录&gt;  把指定文件或目录的日期时间，统统设成和参考文件或目录的日期时间相同；
-t：&lt;日期时间&gt;  使用指定的日期时间，而非现在的时间；
--help：在线帮助；
--version：显示版本信息
</code></pre><p>【参数说明】</p>
<p>参数：文件列表</p>
<p>注意：<br>① 文件可以是目录<br>② 如果文件不存在，则新建一个空文件</p>
<h2 id="3-常见用法与示例"><a href="#3-常见用法与示例" class="headerlink" title="3 常见用法与示例"></a>3 常见用法与示例</h2><h3 id="3-1-常见用法"><a href="#3-1-常见用法" class="headerlink" title="3.1 常见用法"></a>3.1 常见用法</h3><p>1）新建空文件</p>
<pre><code>touch 文件名列表
</code></pre><p>2）更改文件创建时间为指定日期时间</p>
<pre><code>touch -t [CC][YY]MMDDhhmm[.SS]
</code></pre><blockquote>
<ul>
<li><code>CC</code>为年数中的前两位，即”世纪数”；</li>
<li><code>YY</code>为年数的后两位，即某世纪中的年数．如果不给出CC的值，则touch将把年数CCYY限定在1969–2068之内．</li>
<li><code>MM</code>为月数</li>
<li><code>DD</code>为天数</li>
<li><code>hh</code>为小时数(几点)</li>
<li><code>mm</code>为分钟数</li>
<li><code>SS</code>为秒数．此处秒的设定范围是0–61，这样可以处理闰秒．</li>
</ul>
</blockquote>
<p>这些数字组成的时间是环境变量TZ指定的时区中的一个时间．由于系统的限制，早于1970年1月1日的时间是错误的。</p>
<p>3）把指定文件或目录的日期时间，统统设成和参考文件或目录相同的日期时间</p>
<pre><code>touch -r 参考文件 要修改的文件列表
</code></pre><h3 id="3-2-示例"><a href="#3-2-示例" class="headerlink" title="3.2 示例"></a>3.2 示例</h3><p>1）新建空文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[work@testpc test 13:45:26]$ touch aaa</span><br><span class="line">[work@testpc test 13:45:29]$ ll</span><br><span class="line">total 0</span><br><span class="line">-rw-rw-r--. 1 work work 0 Jan  3 13:45 aaa</span><br></pre></td></tr></table></figure>
<p>2）更改文件创建时间为指定日期时间</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[work@testpc test 13:45:42]$ touch -t 201812192204 aaa</span><br><span class="line">[work@testpc test 13:45:46]$</span><br><span class="line">[work@testpc test 13:45:47]$ ll</span><br><span class="line">total 0</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 aaa</span><br></pre></td></tr></table></figure>
<p>3）把指定文件或目录的日期时间，统统设成和参考文件或目录相同的日期时间</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[work@testpc test 13:51:44]$ ll</span><br><span class="line">total 0</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 aaa</span><br><span class="line">-rw-rw-r--. 1 work work 0 Jan  3 13:51 bbb</span><br><span class="line">-rw-rw-r--. 1 work work 0 Jan  3 13:51 ccc</span><br><span class="line">-rw-rw-r--. 1 work work 0 Jan  3 13:51 ddd</span><br><span class="line"></span><br><span class="line">[work@testpc test 13:51:48]$ touch -r aaa bbb ccc ddd</span><br><span class="line">[work@testpc test 13:51:57]$ ll</span><br><span class="line">total 0</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 aaa</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 bbb</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 ccc</span><br><span class="line">-rw-rw-r--. 1 work work 0 Dec 19 22:04 ddd</span><br></pre></td></tr></table></figure>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><ol>
<li>每天一个linux命令（9）：<br>touch 命令：<a href="http://www.cnblogs.com/peida/archive/2012/10/30/2745714.html" target="_blank" rel="noopener">http://www.cnblogs.com/peida/archive/2012/10/30/2745714.html</a></li>
<li><a href="https://wangchujiang.com/linux-command/c/touch.html" target="_blank" rel="noopener">https://wangchujiang.com/linux-command/c/touch.html</a></li>
</ol>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Linux/" rel="tag"># Linux</a>
          
            <a href="/blog/tags/Shell/" rel="tag"># Shell</a>
          
            <a href="/blog/tags/每天一个Linux命令/" rel="tag"># 每天一个Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/01/03/每天一个Linux命令（4）：tree/" rel="next" title="每天一个Linux命令（4）：tree">
                <i class="fa fa-chevron-left"></i> 每天一个Linux命令（4）：tree
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/01/04/每天一个Linux命令（6）：cp/" rel="prev" title="每天一个Linux命令（6）：cp">
                每天一个Linux命令（6）：cp <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">七年弹指间</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives/">
                
                    <span class="site-state-item-count">12</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">7</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">10</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-功能"><span class="nav-text">1 功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-语法格式"><span class="nav-text">2 语法格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-常见用法与示例"><span class="nav-text">3 常见用法与示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-常见用法"><span class="nav-text">3.1 常见用法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-示例"><span class="nav-text">3.2 示例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考资料"><span class="nav-text">参考资料</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">七年弹指间</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v6.6.0</div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script src="/blog/js/src/utils.js?v=6.6.0"></script>

  <script src="/blog/js/src/motion.js?v=6.6.0"></script>



  
  


  <script src="/blog/js/src/affix.js?v=6.6.0"></script>

  <script src="/blog/js/src/schemes/pisces.js?v=6.6.0"></script>



  
  <script src="/blog/js/src/scrollspy.js?v=6.6.0"></script>
<script src="/blog/js/src/post-details.js?v=6.6.0"></script>



  


  <script src="/blog/js/src/bootstrap.js?v=6.6.0"></script>



  



  











  





  

  

  

  

  
  

  
  

  


  
  

  

  

  

  

  

  

</body>
</html>
